package com.nys.cqhttp.util;

public class Chinese2Number {
    public static Integer convert(String chineseText) {
        ChineseCharSequence sequence = ChineseCharSequence.parse(chineseText);
        Integer sum = 0;
        for (int i = 0; i < sequence.size(); i++) {
            ChineseChar chineseChar = sequence.get(i);
            if (chineseChar.isNumber()) {
                if (!chineseChar.getNumber().equals(0)) {
                    if (i + 1 < sequence.size()) {
                        ChineseChar chineseChar1 = sequence.get(i + 1);
                        if (!chineseChar1.isNumber()) {
                            if (sum.equals(0) || sum > chineseChar1.getRate()) {
                                sum = sum + chineseChar.getNumber() * chineseChar1.getRate();
                            } else {
                                sum = sum + chineseChar.getNumber();
                                sum = sum * chineseChar1.getRate();
                            }
                        }
                    } else {
                        sum = sum + chineseChar.getNumber();
                    }
                    if (i + 2 < sequence.size()) {
                        ChineseChar chineseChar1 = sequence.get(i + 1);
                        ChineseChar chineseChar2 = sequence.get(i + 2);
                        if (!chineseChar1.isNumber() && !chineseChar2.isNumber()) {
                            sum = sum * chineseChar2.getRate();
                        }
                    }
                }
            }
        }
        return sum;
    }
}
